package com.code.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
//拓展springmvc
@Configuration
@EnableWebMvc // 如果标注了就会被springmvc全面接管
public class WebMVCConfig implements WebMvcConfigurer {
    @Autowired
    LoginInterceptor loginInterceptor;
    //样式加载不进来加一句话
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //前端主页控制实现，可以加载样式
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**/to/**")//需要拦截的路径

                .excludePathPatterns("/**/to/toLoginIndex")
                .excludePathPatterns("/**/to/getLogin")
                .excludePathPatterns("/**/**/getError")
                .excludePathPatterns("/**/areaFeign/list")
                .excludePathPatterns("/");//排除/doLogin路径

    }
}